// pages/trading/result/result.js
import Router from "../../../class/Router";
import OrderService from "../../../class/service/OrderService";
import Tips from "../../../utils/Tips";


const orderService = new OrderService();
const util = require("../../../utils/util.js")
const storage = require("../../../utils/storage.js")
const constant = require("../../../constant.js")
const notification = require("../../../utils/WxNotificationCenter.js");

Page({

  /**
   * 页面的初始数据
   */
  data: {
    loaded: false,
    successed: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({order: options.order})
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    setTimeout(function(){
      orderService.load(that.data.order).then(data => {
        console.log(data);
        that.setData({
          loaded: true,
          order: data.order,
          successed: data.order.payment_status == 'PAID'
        })
      }, res => {
        Tips.error("同步订单数据失败");
        that.setData({
          loaded: true,
          successed: true
        })
      })
    }, 5000)
  },

  goProduct: function() {
    wx.navigateTo({
      url: '../../../pages/product/detail/detail',
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})